﻿using System;

namespace Framework
{
    public class Command
    {
        public enum Status
        {
            Runing,
            Success,
            Fail
        }

        public event Action<Command> completedEvent;
        public Status status { get; private set; }
        
        protected object _context;
        
        public void Start(object context)
        {
            _context = context;
            status = Status.Runing;
            StartCommand();
        }

        public void Stop()
        {
            if (status == Status.Runing)
            {
                StopCommand();
            }
        }

        protected virtual void StartCommand()
        {
            
        }

        protected virtual void StopCommand()
        {
            
        }

        protected void OnCompleted(Status status)
        {
            this.status = status;
            if (completedEvent != null)
            {
                completedEvent.Invoke(this);
            }
        }
    }
}